var express = require('express');
var router = express.Router();
var mysql = require('mysql');

/* GET home page. */
router.get('/', function(req, res, next) {
    //配置好数据库连接
    var conn = mysql.createConnection({
        host: 'localhost',
        user:'root',
        password:'123456',
        database:'stumanager'
    });
    conn.connect(err=>{
        if (err) console.log('数据库连接失败！\n' + err.stack);
        else console.log('数据库连接成功！');
    });
    var strSQL = 'select * from student'
    conn.query(strSQL, (err, result)=>{
        if(err) {
            console.log('查询出错！');
            conn.end();
            res.send('查询出错！');
        }else{
            // console.log(result);
            // res.send(result);
            res.render('studentlist', {
                title: '学生信息表',
                data: result
            })
        }
    });

});



module.exports = router;
